<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="language" content="en" />
        <link href="./assets/ffd55088/css/bootstrap.css" rel="stylesheet">
<link href="./assets/5cf9384a/solarized_light.css" rel="stylesheet">
<link href="./assets/6c54116e/style.css" rel="stylesheet">
<script src="./assets/a44cef0f/jquery.js"></script>
<script src="./assets/ffd55088/js/bootstrap.js"></script>
<script src="./assets/8ac4e28a/jssearch.js"></script>    <title>Core Validators - Special Topics - The Definitive Guide to Yii 2.0</title>
</head>
<body>

<div class="wrap">
    <nav id="w16" class="navbar-inverse navbar-fixed-top navbar" role="navigation"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#w16-collapse"><span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span></button><a class="navbar-brand" href="./index.html">The Definitive Guide to Yii 2.0</a></div><div id="w16-collapse" class="collapse navbar-collapse"><ul id="w17" class="navbar-nav nav"><li><a href="./index.html">Class reference</a></li>
<li class="dropdown"><a class="dropdown-toggle" href="#" data-toggle="dropdown">Extensions <b class="caret"></b></a><ul id="w18" class="dropdown-menu"><li><a href="./ext-apidoc-index.html" tabindex="-1">apidoc</a></li>
<li><a href="./ext-authclient-index.html" tabindex="-1">authclient</a></li>
<li><a href="./ext-bootstrap-index.html" tabindex="-1">bootstrap</a></li>
<li><a href="./ext-codeception-index.html" tabindex="-1">codeception</a></li>
<li><a href="./ext-debug-index.html" tabindex="-1">debug</a></li>
<li><a href="./ext-elasticsearch-index.html" tabindex="-1">elasticsearch</a></li>
<li><a href="./ext-faker-index.html" tabindex="-1">faker</a></li>
<li><a href="./ext-gii-index.html" tabindex="-1">gii</a></li>
<li><a href="./ext-imagine-index.html" tabindex="-1">imagine</a></li>
<li><a href="./ext-jui-index.html" tabindex="-1">jui</a></li>
<li><a href="./ext-mongodb-index.html" tabindex="-1">mongodb</a></li>
<li><a href="./ext-redis-index.html" tabindex="-1">redis</a></li>
<li><a href="./ext-smarty-index.html" tabindex="-1">smarty</a></li>
<li><a href="./ext-sphinx-index.html" tabindex="-1">sphinx</a></li>
<li><a href="./ext-swiftmailer-index.html" tabindex="-1">swiftmailer</a></li>
<li><a href="./ext-twig-index.html" tabindex="-1">twig</a></li></ul></li>
<li><a href="./guide-README.html">Guide</a></li></ul><div class="navbar-form navbar-left" role="search">
  <div class="form-group">
    <input id="searchbox" type="text" class="form-control" placeholder="Search">
  </div>
</div>
</div></nav>
    <div id="search-resultbox" style="display: none;" class="modal-content">
        <ul id="search-results">
        </ul>
    </div>

    
<div class="row">
    <div class="col-md-2">
                <div id="navigation" class="list-group"><a class="list-group-item" href="#navigation-0" data-toggle="collapse" data-parent="#navigation">Introduction <b class="caret"></b></a><div id="navigation-0" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-intro-yii.html">About Yii</a>
<a class="list-group-item" href="./guide-intro-upgrade-from-v1.html">Upgrading from Version 1.1</a></div>
<a class="list-group-item" href="#navigation-1" data-toggle="collapse" data-parent="#navigation">Getting Started <b class="caret"></b></a><div id="navigation-1" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-start-installation.html">Installing Yii</a>
<a class="list-group-item" href="./guide-start-workflow.html">Running Applications</a>
<a class="list-group-item" href="./guide-start-hello.html">Saying Hello</a>
<a class="list-group-item" href="./guide-start-forms.html">Working with Forms</a>
<a class="list-group-item" href="./guide-start-databases.html">Working with Databases</a>
<a class="list-group-item" href="./guide-start-gii.html">Generating Code with Gii</a>
<a class="list-group-item" href="./guide-start-looking-ahead.html">Looking Ahead</a></div>
<a class="list-group-item" href="#navigation-2" data-toggle="collapse" data-parent="#navigation">Application Structure <b class="caret"></b></a><div id="navigation-2" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-structure-overview.html">Overview</a>
<a class="list-group-item" href="./guide-structure-entry-scripts.html">Entry Scripts</a>
<a class="list-group-item" href="./guide-structure-applications.html">Applications</a>
<a class="list-group-item" href="./guide-structure-application-components.html">Application Components</a>
<a class="list-group-item" href="./guide-structure-controllers.html">Controllers</a>
<a class="list-group-item" href="./guide-structure-models.html">Models</a>
<a class="list-group-item" href="./guide-structure-views.html">Views</a>
<a class="list-group-item" href="./guide-structure-modules.html">Modules</a>
<a class="list-group-item" href="./guide-structure-filters.html">Filters</a>
<a class="list-group-item" href="./guide-structure-widgets.html">Widgets</a>
<a class="list-group-item" href="./guide-structure-assets.html">Assets</a>
<a class="list-group-item" href="./guide-structure-extensions.html">Extensions</a></div>
<a class="list-group-item" href="#navigation-3" data-toggle="collapse" data-parent="#navigation">Handling Requests <b class="caret"></b></a><div id="navigation-3" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-runtime-overview.html">Overview</a>
<a class="list-group-item" href="./guide-runtime-bootstrapping.html">Bootstrapping</a>
<a class="list-group-item" href="./guide-runtime-routing.html">Routing and URL Creation</a>
<a class="list-group-item" href="./guide-runtime-requests.html">Requests</a>
<a class="list-group-item" href="./guide-runtime-responses.html">Responses</a>
<a class="list-group-item" href="./guide-runtime-sessions-cookies.html">Sessions and Cookies</a>
<a class="list-group-item" href="./guide-runtime-handling-errors.html">Handling Errors</a>
<a class="list-group-item" href="./guide-runtime-logging.html">Logging</a></div>
<a class="list-group-item" href="#navigation-4" data-toggle="collapse" data-parent="#navigation">Key Concepts <b class="caret"></b></a><div id="navigation-4" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-concept-components.html">Components</a>
<a class="list-group-item" href="./guide-concept-properties.html">Properties</a>
<a class="list-group-item" href="./guide-concept-events.html">Events</a>
<a class="list-group-item" href="./guide-concept-behaviors.html">Behaviors</a>
<a class="list-group-item" href="./guide-concept-configurations.html">Configurations</a>
<a class="list-group-item" href="./guide-concept-aliases.html">Aliases</a>
<a class="list-group-item" href="./guide-concept-autoloading.html">Class Autoloading</a>
<a class="list-group-item" href="./guide-concept-service-locator.html">Service Locator</a>
<a class="list-group-item" href="./guide-concept-di-container.html">Dependency Injection Container</a></div>
<a class="list-group-item" href="#navigation-5" data-toggle="collapse" data-parent="#navigation">Working with Databases <b class="caret"></b></a><div id="navigation-5" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-db-dao.html">Data Access Objects</a>
<a class="list-group-item" href="./guide-db-query-builder.html">Query Builder</a>
<a class="list-group-item" href="./guide-db-active-record.html">Active Record</a>
<a class="list-group-item" href="./guide-db-migrations.html">Migrations</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-sphinx/blob/master/docs/guide/README.md">Sphinx</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-redis/blob/master/docs/guide/README.md">Redis</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-mongodb/blob/master/docs/guide/README.md">MongoDB</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-elasticsearch/blob/master/docs/guide/README.md">ElasticSearch</a></div>
<a class="list-group-item" href="#navigation-6" data-toggle="collapse" data-parent="#navigation">Getting Data from Users <b class="caret"></b></a><div id="navigation-6" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-input-forms.html">Creating Forms</a>
<a class="list-group-item" href="./guide-input-validation.html">Validating Input</a>
<a class="list-group-item" href="./guide-input-file-upload.html">Uploading Files</a>
<a class="list-group-item" href="./guide-input-tabular-input.html">Collecting Tabular Input</a>
<a class="list-group-item" href="./guide-input-multiple-models.html">Getting Data for Multiple Models</a></div>
<a class="list-group-item" href="#navigation-7" data-toggle="collapse" data-parent="#navigation">Displaying Data <b class="caret"></b></a><div id="navigation-7" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-output-formatting.html">Data Formatting</a>
<a class="list-group-item" href="./guide-output-pagination.html">Pagination</a>
<a class="list-group-item" href="./guide-output-sorting.html">Sorting</a>
<a class="list-group-item" href="./guide-output-data-providers.html">Data Providers</a>
<a class="list-group-item" href="./guide-output-data-widgets.html">Data Widgets</a>
<a class="list-group-item" href="./guide-output-client-scripts.html">Working with Client Scripts</a>
<a class="list-group-item" href="./guide-output-theming.html">Theming</a></div>
<a class="list-group-item" href="#navigation-8" data-toggle="collapse" data-parent="#navigation">Security <b class="caret"></b></a><div id="navigation-8" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-security-overview.html">Overview</a>
<a class="list-group-item" href="./guide-security-authentication.html">Authentication</a>
<a class="list-group-item" href="./guide-security-authorization.html">Authorization</a>
<a class="list-group-item" href="./guide-security-passwords.html">Working with Passwords</a>
<a class="list-group-item" href="./guide-security-cryptography.html">Cryptography</a>
<a class="list-group-item" href="./guide-structure-views.html#security">Views security</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-authclient/blob/master/docs/guide/README.md">Auth Clients</a>
<a class="list-group-item" href="./guide-security-best-practices.html">Best Practices</a></div>
<a class="list-group-item" href="#navigation-9" data-toggle="collapse" data-parent="#navigation">Caching <b class="caret"></b></a><div id="navigation-9" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-caching-overview.html">Overview</a>
<a class="list-group-item" href="./guide-caching-data.html">Data Caching</a>
<a class="list-group-item" href="./guide-caching-fragment.html">Fragment Caching</a>
<a class="list-group-item" href="./guide-caching-page.html">Page Caching</a>
<a class="list-group-item" href="./guide-caching-http.html">HTTP Caching</a></div>
<a class="list-group-item" href="#navigation-10" data-toggle="collapse" data-parent="#navigation">RESTful Web Services <b class="caret"></b></a><div id="navigation-10" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-rest-quick-start.html">Quick Start</a>
<a class="list-group-item" href="./guide-rest-resources.html">Resources</a>
<a class="list-group-item" href="./guide-rest-controllers.html">Controllers</a>
<a class="list-group-item" href="./guide-rest-routing.html">Routing</a>
<a class="list-group-item" href="./guide-rest-response-formatting.html">Response Formatting</a>
<a class="list-group-item" href="./guide-rest-authentication.html">Authentication</a>
<a class="list-group-item" href="./guide-rest-rate-limiting.html">Rate Limiting</a>
<a class="list-group-item" href="./guide-rest-versioning.html">Versioning</a>
<a class="list-group-item" href="./guide-rest-error-handling.html">Error Handling</a></div>
<a class="list-group-item" href="#navigation-11" data-toggle="collapse" data-parent="#navigation">Development Tools <b class="caret"></b></a><div id="navigation-11" class="submenu panel-collapse collapse"><a class="list-group-item" href="https://github.com/yiisoft/yii2-debug/blob/master/docs/guide/README.md">Debug Toolbar and Debugger</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/README.md">Generating Code using Gii</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-apidoc">Generating API Documentation</a></div>
<a class="list-group-item" href="#navigation-12" data-toggle="collapse" data-parent="#navigation">Testing <b class="caret"></b></a><div id="navigation-12" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-test-overview.html">Overview</a>
<a class="list-group-item" href="./guide-test-environment-setup.html">Testing environment setup</a>
<a class="list-group-item" href="./guide-test-unit.html">Unit Tests</a>
<a class="list-group-item" href="./guide-test-functional.html">Functional Tests</a>
<a class="list-group-item" href="./guide-test-acceptance.html">Acceptance Tests</a>
<a class="list-group-item" href="./guide-test-fixtures.html">Fixtures</a></div>
<a class="list-group-item active" href="#navigation-13" data-toggle="collapse" data-parent="#navigation">Special Topics <b class="caret"></b></a><div id="navigation-13" class="submenu panel-collapse collapse in"><a class="list-group-item" href="https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md">Advanced Project Template</a>
<a class="list-group-item" href="./guide-tutorial-start-from-scratch.html">Building Application from Scratch</a>
<a class="list-group-item" href="./guide-tutorial-console.html">Console Commands</a>
<a class="list-group-item active" href="./guide-tutorial-core-validators.html">Core Validators</a>
<a class="list-group-item" href="./guide-tutorial-i18n.html">Internationalization</a>
<a class="list-group-item" href="./guide-tutorial-mailing.html">Mailing</a>
<a class="list-group-item" href="./guide-tutorial-performance-tuning.html">Performance Tuning</a>
<a class="list-group-item" href="./guide-tutorial-shared-hosting.html">Shared Hosting Environment</a>
<a class="list-group-item" href="./guide-tutorial-template-engines.html">Template Engines</a>
<a class="list-group-item" href="./guide-tutorial-yii-integration.html">Working with Third-Party Code</a></div>
<a class="list-group-item" href="#navigation-14" data-toggle="collapse" data-parent="#navigation">Widgets <b class="caret"></b></a><div id="navigation-14" class="submenu panel-collapse collapse"><a class="list-group-item" href="https://github.com/yiisoft/yii2-bootstrap/blob/master/docs/guide/README.md">Bootstrap Widgets</a>
<a class="list-group-item" href="https://github.com/yiisoft/yii2-jui/blob/master/docs/guide/README.md">jQuery UI Widgets</a></div>
<a class="list-group-item" href="#navigation-15" data-toggle="collapse" data-parent="#navigation">Helpers <b class="caret"></b></a><div id="navigation-15" class="submenu panel-collapse collapse"><a class="list-group-item" href="./guide-helper-overview.html">Overview</a>
<a class="list-group-item" href="./guide-helper-array.html">ArrayHelper</a>
<a class="list-group-item" href="./guide-helper-html.html">Html</a>
<a class="list-group-item" href="./guide-helper-url.html">Url</a></div></div>    </div>
    <div class="col-md-9 guide-content" role="main">
        <h1>Core Validators <span id="core-validators"></span><a href="#core-validators" class="hashlink">&para;</a></h1>
<div class="toc"><ol><li><a href="#boolean">boolean</a></li>
<li><a href="#captcha">captcha</a></li>
<li><a href="#compare">compare</a></li>
<li><a href="#date">date</a></li>
<li><a href="#default">default</a></li>
<li><a href="#double">double</a></li>
<li><a href="#each">each</a></li>
<li><a href="#email">email</a></li>
<li><a href="#exist">exist</a></li>
<li><a href="#file">file</a></li>
<li><a href="#filter">filter</a></li>
<li><a href="#image">image</a></li>
<li><a href="#ip">ip</a></li>
<li><a href="#in">in</a></li>
<li><a href="#integer">integer</a></li>
<li><a href="#match">match</a></li>
<li><a href="#number">number</a></li>
<li><a href="#required">required</a></li>
<li><a href="#safe">safe</a></li>
<li><a href="#string">string</a></li>
<li><a href="#trim">trim</a></li>
<li><a href="#unique">unique</a></li>
<li><a href="#url">url</a></li></ol></div>
<p>Yii provides a set of commonly used core validators, found primarily under the <code>yii\validators</code> namespace.
Instead of using lengthy validator class names, you may use <em>aliases</em> to specify the use of these core
validators. For example, you can use the alias <code>required</code> to refer to the <a href="./yii-validators-requiredvalidator.html">yii\validators\RequiredValidator</a> class:</p>
<pre><code class="hljs php language-php"><span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rules</span><span class="hljs-params">()</span>
</span>{
    <span class="hljs-keyword">return</span> [
        [[<span class="hljs-string">'email'</span>, <span class="hljs-string">'password'</span>], <span class="hljs-string">'required'</span>],
    ];
}
</code></pre>
<p>The <a href="./yii-validators-validator.html#$builtInValidators-detail">yii\validators\Validator::$builtInValidators</a> property declares all supported validator aliases.</p>
<p>In the following, we will describe the main usage and properties of every core validator.</p>
<h2><a href="./yii-validators-booleanvalidator.html">boolean</a>  <span id="boolean"></span><a href="#boolean" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "selected" is either 0 or 1, regardless of data type</span>
    [<span class="hljs-string">'selected'</span>, <span class="hljs-string">'boolean'</span>],

    <span class="hljs-comment">// checks if "deleted" is of boolean type, either true or false</span>
    [<span class="hljs-string">'deleted'</span>, <span class="hljs-string">'boolean'</span>, <span class="hljs-string">'trueValue'</span> =&gt; <span class="hljs-keyword">true</span>, <span class="hljs-string">'falseValue'</span> =&gt; <span class="hljs-keyword">false</span>, <span class="hljs-string">'strict'</span> =&gt; <span class="hljs-keyword">true</span>],
]
</code></pre>
<p>This validator checks if the input value is a boolean.</p>
<ul>
<li><code>trueValue</code>: the value representing <em>true</em>. Defaults to <code>'1'</code>.</li>
<li><code>falseValue</code>: the value representing <em>false</em>. Defaults to <code>'0'</code>.</li>
<li><code>strict</code>: whether the type of the input value should match that of <code>trueValue</code> and <code>falseValue</code>. Defaults to <code>false</code>.</li>
</ul>
<blockquote class="note"><p><strong>Note: </strong>Because data input submitted via HTML forms are all strings, you normally should leave the
  <a href="./yii-validators-booleanvalidator.html#$strict-detail">strict</a> property as false.</p>
</blockquote>
<h2><a href="./yii-captcha-captchavalidator.html">captcha</a>  <span id="captcha"></span><a href="#captcha" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    [<span class="hljs-string">'verificationCode'</span>, <span class="hljs-string">'captcha'</span>],
]
</code></pre>
<p>This validator is usually used together with <a href="./yii-captcha-captchaaction.html">yii\captcha\CaptchaAction</a> and <a href="./yii-captcha-captcha.html">yii\captcha\Captcha</a>
to make sure an input is the same as the verification code displayed by <a href="./yii-captcha-captcha.html">CAPTCHA</a> widget.</p>
<ul>
<li><code>caseSensitive</code>: whether the comparison of the verification code is case sensitive. Defaults to false.</li>
<li><code>captchaAction</code>: the <a href="guide-structure-controllers.html#routes">route</a> corresponding to the
<a href="./yii-captcha-captchaaction.html">CAPTCHA action</a> that renders the CAPTCHA image. Defaults to <code>'site/captcha'</code>.</li>
<li><code>skipOnEmpty</code>: whether the validation can be skipped if the input is empty. Defaults to false,
which means the input is required.</li>
</ul>
<h2><a href="./yii-validators-comparevalidator.html">compare</a>  <span id="compare"></span><a href="#compare" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// validates if the value of "password" attribute equals to that of "password_repeat"</span>
    [<span class="hljs-string">'password'</span>, <span class="hljs-string">'compare'</span>],

    <span class="hljs-comment">// validates if age is greater than or equal to 30</span>
    [<span class="hljs-string">'age'</span>, <span class="hljs-string">'compare'</span>, <span class="hljs-string">'compareValue'</span> =&gt; <span class="hljs-number">30</span>, <span class="hljs-string">'operator'</span> =&gt; <span class="hljs-string">'&gt;='</span>],
]
</code></pre>
<p>This validator compares the specified input value with another one and make sure if their relationship
is as specified by the <code>operator</code> property.</p>
<ul>
<li><code>compareAttribute</code>: the name of the attribute whose value should be compared with. When the validator
is being used to validate an attribute, the default value of this property would be the name of
the attribute suffixed with <code>_repeat</code>. For example, if the attribute being validated is <code>password</code>,
then this property will default to <code>password_repeat</code>.</li>
<li><code>compareValue</code>: a constant value that the input value should be compared with. When both
of this property and <code>compareAttribute</code> are specified, this property will take precedence.</li>
<li><code>operator</code>: the comparison operator. Defaults to <code>==</code>, meaning checking if the input value is equal
to that of <code>compareAttribute</code> or <code>compareValue</code>. The following operators are supported:<ul>
<li><code>==</code>: check if two values are equal. The comparison is done is non-strict mode.</li>
<li><code>===</code>: check if two values are equal. The comparison is done is strict mode.</li>
<li><code>!=</code>: check if two values are NOT equal. The comparison is done is non-strict mode.</li>
<li><code>!==</code>: check if two values are NOT equal. The comparison is done is strict mode.</li>
<li><code>&gt;</code>: check if value being validated is greater than the value being compared with.</li>
<li><code>&gt;=</code>: check if value being validated is greater than or equal to the value being compared with.</li>
<li><code>&lt;</code>: check if value being validated is less than the value being compared with.</li>
<li><code>&lt;=</code>: check if value being validated is less than or equal to the value being compared with.</li>
</ul>
</li>
</ul>
<h3>Comparing date values <span id="comparing-date-values"></span><a href="#comparing-date-values" class="hashlink">&para;</a></h3><p>The compare validator can only be used to compare strings and numbers. If you need to compare values
like dates you have two options. For comparing a date against a fixed value, you can simply use the
<a href="./yii-validators-datevalidator.html">date</a> validator and specify its
<a href="./yii-validators-datevalidator.html#$min-detail">$min</a> or <a href="./yii-validators-datevalidator.html#$max-detail">$max</a> property.
If you need to compare two dates entered in the form, e.g. a <code>fromDate</code> and a <code>toDate</code> field,
you can use a combination of compare and date validator like the following:</p>
<pre><code class="hljs php language-php">[<span class="hljs-string">'fromDate'</span>, <span class="hljs-string">'date'</span>, <span class="hljs-string">'timestampAttribute'</span> =&gt; <span class="hljs-string">'fromDate'</span>],
[<span class="hljs-string">'toDate'</span>, <span class="hljs-string">'date'</span>, <span class="hljs-string">'timestampAttribute'</span> =&gt; <span class="hljs-string">'toDate'</span>],
[<span class="hljs-string">'fromDate'</span>, <span class="hljs-string">'compare'</span>, <span class="hljs-string">'compareAttribute'</span> =&gt; <span class="hljs-string">'toDate'</span>, <span class="hljs-string">'operator'</span> =&gt; <span class="hljs-string">'&lt;'</span>, <span class="hljs-string">'enableClientValidation'</span> =&gt; <span class="hljs-keyword">false</span>],
</code></pre>
<p>As validators are executed in the order they are specified this will first validate that the values entered in
<code>fromDate</code> and <code>toDate</code> are valid date values and if so, they will be converted into a machine readable format.
Afterwards these two values are compared with the compare validator.
Client validation is not enabled as this will only work on the server side because the date validator currently does not
provide client validation, so <a href="./yii-validators-validator.html#$enableClientValidation-detail">$enableClientValidation</a>
is set to <code>false</code> on the compare validator too.</p>
<h2><a href="./yii-validators-datevalidator.html">date</a>  <span id="date"></span><a href="#date" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    [[<span class="hljs-string">'from_date'</span>, <span class="hljs-string">'to_date'</span>], <span class="hljs-string">'date'</span>],
]
</code></pre>
<p>This validator checks if the input value is a date, time or datetime in a proper format.
Optionally, it can convert the input value into a UNIX timestamp or other machine readable format and store it in an attribute
specified via <a href="./yii-validators-datevalidator.html#$timestampAttribute-detail">timestampAttribute</a>.</p>
<ul>
<li><p><code>format</code>: the date/time format that the value being validated should be in.
 This can be a date time pattern as described in the <a href="http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax">ICU manual</a>.
 Alternatively this can be a string prefixed with <code>php:</code> representing a format that can be recognized by the PHP
 <code>Datetime</code> class. Please refer to <a href="http://php.net/manual/en/datetime.createfromformat.php">http://php.net/manual/en/datetime.createfromformat.php</a> on supported formats.
 If this is not set, it will take the value of <code>Yii::$app-&gt;formatter-&gt;dateFormat</code>.
 See the <a href="./yii-validators-datevalidator.html#$format-detail">API documentation</a> for more details.</p>
</li>
<li><p><code>timestampAttribute</code>: the name of the attribute to which this validator may assign the UNIX timestamp
converted from the input date/time. This can be the same attribute as the one being validated. If this is the case,
the original value will be overwritten with the timestamp value after validation.
See <a href="https://github.com/yiisoft/yii2-jui/blob/master/docs/guide/topics-date-picker.md">"Handling date input with the DatePicker"</a> for a usage example.</p>
<p>Since version 2.0.4, a format and timezone can be specified for this attribute using
<a href="./yii-validators-datevalidator.html#$timestampAttributeFormat-detail">$timestampAttributeFormat</a> and
<a href="./yii-validators-datevalidator.html#$timestampAttributeTimeZone-detail">$timestampAttributeTimeZone</a>.</p>
</li>
<li><p>Since version 2.0.4 it is also possible to specify a <a href="./yii-validators-datevalidator.html#$min-detail">minimum</a> or
<a href="./yii-validators-datevalidator.html#$max-detail">maximum</a> timestamp.</p>
</li>
</ul>
<p>In case the input is optional you may also want to add a <a href="#default">default value filter</a> in addition to the date validator
to ensure empty input is stored as <code>NULL</code>. Other wise you may end up with dates like <code>0000-00-00</code> in your database
or <code>1970-01-01</code> in the input field of a date picker.</p>
<pre><code class="hljs php language-php">[
    [[<span class="hljs-string">'from_date'</span>, <span class="hljs-string">'to_date'</span>], <span class="hljs-string">'default'</span>, <span class="hljs-string">'value'</span> =&gt; <span class="hljs-keyword">null</span>],
    [[<span class="hljs-string">'from_date'</span>, <span class="hljs-string">'to_date'</span>], <span class="hljs-string">'date'</span>],
],
</code></pre>
<h2><a href="./yii-validators-defaultvaluevalidator.html">default</a>  <span id="default"></span><a href="#default" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// set "age" to be null if it is empty</span>
    [<span class="hljs-string">'age'</span>, <span class="hljs-string">'default'</span>, <span class="hljs-string">'value'</span> =&gt; <span class="hljs-keyword">null</span>],

    <span class="hljs-comment">// set "country" to be "USA" if it is empty</span>
    [<span class="hljs-string">'country'</span>, <span class="hljs-string">'default'</span>, <span class="hljs-string">'value'</span> =&gt; <span class="hljs-string">'USA'</span>],

    <span class="hljs-comment">// assign "from" and "to" with a date 3 days and 6 days from today, if they are empty</span>
    [[<span class="hljs-string">'from'</span>, <span class="hljs-string">'to'</span>], <span class="hljs-string">'default'</span>, <span class="hljs-string">'value'</span> =&gt; <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(<span class="hljs-variable">$model</span>, <span class="hljs-variable">$attribute</span>)</span> </span>{
        <span class="hljs-keyword">return</span> date(<span class="hljs-string">'Y-m-d'</span>, strtotime(<span class="hljs-variable">$attribute</span> === <span class="hljs-string">'to'</span> ? <span class="hljs-string">'+3 days'</span> : <span class="hljs-string">'+6 days'</span>));
    }],
]
</code></pre>
<p>This validator does not validate data. Instead, it assigns a default value to the attributes being validated
if the attributes are empty.</p>
<ul>
<li><code>value</code>: the default value or a PHP callable that returns the default value which will be assigned to
the attributes being validated if they are empty. The signature of the PHP callable should be as follows,</li>
</ul>
<pre><code class="hljs php language-php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-variable">$model</span>, <span class="hljs-variable">$attribute</span>)</span> </span>{
    <span class="hljs-comment">// ... compute $value ...</span>
    <span class="hljs-keyword">return</span> <span class="hljs-variable">$value</span>;
}
</code></pre>
<blockquote class="info"><p><strong>Info: </strong>How to determine if a value is empty or not is a separate topic covered
  in the <a href="guide-input-validation.html#handling-empty-inputs">Empty Values</a> section.</p>
</blockquote>
<h2><a href="./yii-validators-numbervalidator.html">double</a>  <span id="double"></span><a href="#double" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "salary" is a double number</span>
    [<span class="hljs-string">'salary'</span>, <span class="hljs-string">'double'</span>],
]
</code></pre>
<p>This validator checks if the input value is a double number. It is equivalent to the <a href="#number">number</a> validator.</p>
<ul>
<li><code>max</code>: the upper limit (inclusive) of the value. If not set, it means the validator does not check the upper limit.</li>
<li><code>min</code>: the lower limit (inclusive) of the value. If not set, it means the validator does not check the lower limit.</li>
</ul>
<h2><a href="./yii-validators-eachvalidator.html">each</a>  <span id="each"></span><a href="#each" class="hashlink">&para;</a></h2><blockquote class="info"><p><strong>Info: </strong>This validator has been available since version 2.0.4.</p>
</blockquote>
<pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if every category ID is an integer</span>
    [<span class="hljs-string">'categoryIDs'</span>, <span class="hljs-string">'each'</span>, <span class="hljs-string">'rule'</span> =&gt; [<span class="hljs-string">'integer'</span>]],
]
</code></pre>
<p>This validator only works with an array attribute. It validates if <em>every</em> element of the array can be successfully
validated by a specified validation rule. In the above example, the <code>categoryIDs</code> attribute must take an array value
and each array element will be validated by the <code>integer</code> validation rule.</p>
<ul>
<li><code>rule</code>: an array specifying a validation rule. The first element in the array specifies the class name or
the alias of the validator. The rest of the name-value pairs in the array are used to configure the validator object.</li>
<li><code>allowMessageFromRule</code>: whether to use the error message returned by the embedded validation rule. Defaults to true.
If false, it will use <code>message</code> as the error message.</li>
</ul>
<blockquote class="note"><p><strong>Note: </strong>If the attribute value is not an array, it is considered validation fails and the <code>message</code> will be returned
  as the error message.</p>
</blockquote>
<h2><a href="./yii-validators-emailvalidator.html">email</a>  <span id="email"></span><a href="#email" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "email" is a valid email address</span>
    [<span class="hljs-string">'email'</span>, <span class="hljs-string">'email'</span>],
]
</code></pre>
<p>This validator checks if the input value is a valid email address.</p>
<ul>
<li><code>allowName</code>: whether to allow name in the email address (e.g. <code>John Smith &lt;john.smith@example.com&gt;</code>). Defaults to false.</li>
<li><code>checkDNS</code>, whether to check whether the email's domain exists and has either an A or MX record.
Be aware that this check may fail due to temporary DNS problems, even if the email address is actually valid.
Defaults to false.</li>
<li><code>enableIDN</code>, whether the validation process should take into account IDN (internationalized domain names).
Defaults to false. Note that in order to use IDN validation you have to install and enable the <code>intl</code> PHP extension,
or an exception would be thrown.</li>
</ul>
<h2><a href="./yii-validators-existvalidator.html">exist</a>  <span id="exist"></span><a href="#exist" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// a1 needs to exist in the column represented by the "a1" attribute</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'exist'</span>],

    <span class="hljs-comment">// a1 needs to exist, but its value will use a2 to check for the existence</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'exist'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; <span class="hljs-string">'a2'</span>],

    <span class="hljs-comment">// a1 and a2 need to exist together, and they both will receive error message</span>
    [[<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>], <span class="hljs-string">'exist'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>]],

    <span class="hljs-comment">// a1 and a2 need to exist together, only a1 will receive error message</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'exist'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>]],

    <span class="hljs-comment">// a1 needs to exist by checking the existence of both a2 and a3 (using a1 value)</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'exist'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a2'</span>, <span class="hljs-string">'a1'</span> =&gt; <span class="hljs-string">'a3'</span>]],

    <span class="hljs-comment">// a1 needs to exist. If a1 is an array, then every element of it must exist.</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'exist'</span>, <span class="hljs-string">'allowArray'</span> =&gt; <span class="hljs-keyword">true</span>],
]
</code></pre>
<p>This validator checks if the input value can be found in a table column represented by
an <a href="guide-db-active-record.html">Active Record</a> attribute. You can use <code>targetAttribute</code> to specify the
<a href="guide-db-active-record.html">Active Record</a> attribute and <code>targetClass</code> the corresponding <a href="guide-db-active-record.html">Active Record</a>
class. If you do not specify them, they will take the values of the attribute and the model class being validated.</p>
<p>You can use this validator to validate against a single column or multiple columns (i.e., the combination of
multiple attribute values should exist).</p>
<ul>
<li><code>targetClass</code>: the name of the <a href="guide-db-active-record.html">Active Record</a> class that should be used
to look for the input value being validated. If not set, the class of the model currently being validated will be used.</li>
<li><code>targetAttribute</code>: the name of the attribute in <code>targetClass</code> that should be used to validate the existence
of the input value. If not set, it will use the name of the attribute currently being validated.
You may use an array to validate the existence of multiple columns at the same time. The array values
are the attributes that will be used to validate the existence, while the array keys are the attributes
whose values are to be validated. If the key and the value are the same, you can just specify the value.</li>
<li><code>filter</code>: additional filter to be applied to the DB query used to check the existence of the input value.
This can be a string or an array representing the additional query condition (refer to <a href="./yii-db-query.html#where()-detail">yii\db\Query::where()</a>
on the format of query condition), or an anonymous function with the signature <code>function ($query)</code>, where <code>$query</code>
is the <a href="./yii-db-query.html">Query</a> object that you can modify in the function.</li>
<li><code>allowArray</code>: whether to allow the input value to be an array. Defaults to false. If this property is true
and the input is an array, then every element of the array must exist in the target column. Note that
this property cannot be set true if you are validating against multiple columns by setting <code>targetAttribute</code> as an array.</li>
</ul>
<h2><a href="./yii-validators-filevalidator.html">file</a>  <span id="file"></span><a href="#file" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "primaryImage" is an uploaded image file in PNG, JPG or GIF format.</span>
    <span class="hljs-comment">// the file size must be less than 1MB</span>
    [<span class="hljs-string">'primaryImage'</span>, <span class="hljs-string">'file'</span>, <span class="hljs-string">'extensions'</span> =&gt; [<span class="hljs-string">'png'</span>, <span class="hljs-string">'jpg'</span>, <span class="hljs-string">'gif'</span>], <span class="hljs-string">'maxSize'</span> =&gt; <span class="hljs-number">1024</span>*<span class="hljs-number">1024</span>],
]
</code></pre>
<p>This validator checks if the input is a valid uploaded file.</p>
<ul>
<li><code>extensions</code>: a list of file name extensions that are allowed to be uploaded. This can be either
an array or a string consisting of file extension names separated by space or comma (e.g. "gif, jpg").
Extension names are case-insensitive. Defaults to null, meaning all file name
extensions are allowed.</li>
<li><code>mimeTypes</code>: a list of file MIME types that are allowed to be uploaded. This can be either an array
or a string consisting of file MIME types separated by space or comma (e.g. "image/jpeg, image/png").
The wildcard mask with the special character <code>*</code> can be used to match groups of mime types.
For example <code>image/*</code> will pass all mime types, that begin with <code>image/</code> (e.g. <code>image/jpeg</code>, <code>image/png</code>).
Mime type names are case-insensitive. Defaults to null, meaning all MIME types are allowed.
For more details, please refer to <a href="http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types">common media types</a>.</li>
<li><code>minSize</code>: the minimum number of bytes required for the uploaded file. Defaults to null, meaning no lower limit.</li>
<li><code>maxSize</code>: the maximum number of bytes allowed for the uploaded file. Defaults to null, meaning no upper limit.</li>
<li><code>maxFiles</code>: the maximum number of files that the given attribute can hold. Defaults to 1, meaning
the input must be a single uploaded file. If it is greater than 1, then the input must be an array
consisting of at most <code>maxFiles</code> number of uploaded files.</li>
<li><code>checkExtensionByMimeType</code>: whether to check the file extension by the file's MIME type. If the extension produced by
MIME type check differs from the uploaded file extension, the file will be considered as invalid. Defaults to true,
meaning perform such check.</li>
</ul>
<p><code>FileValidator</code> is used together with <a href="./yii-web-uploadedfile.html">yii\web\UploadedFile</a>. Please refer to the <a href="guide-input-file-upload.html">Uploading Files</a>
section for complete coverage about uploading files and performing validation about the uploaded files.</p>
<h2><a href="./yii-validators-filtervalidator.html">filter</a>  <span id="filter"></span><a href="#filter" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// trim "username" and "email" inputs</span>
    [[<span class="hljs-string">'username'</span>, <span class="hljs-string">'email'</span>], <span class="hljs-string">'filter'</span>, <span class="hljs-string">'filter'</span> =&gt; <span class="hljs-string">'trim'</span>, <span class="hljs-string">'skipOnArray'</span> =&gt; <span class="hljs-keyword">true</span>],

    <span class="hljs-comment">// normalize "phone" input</span>
    [<span class="hljs-string">'phone'</span>, <span class="hljs-string">'filter'</span>, <span class="hljs-string">'filter'</span> =&gt; <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">(<span class="hljs-variable">$value</span>)</span> </span>{
        <span class="hljs-comment">// normalize phone input here</span>
        <span class="hljs-keyword">return</span> <span class="hljs-variable">$value</span>;
    }],
]
</code></pre>
<p>This validator does not validate data. Instead, it applies a filter on the input value and assigns it
back to the attribute being validated.</p>
<ul>
<li><code>filter</code>: a PHP callback that defines a filter. This can be a global function name, an anonymous function, etc.
The function signature must be <code>function ($value) { return $newValue; }</code>. This property must be set.</li>
<li><code>skipOnArray</code>: whether to skip the filter if the input value is an array. Defaults to false.
Note that if the filter cannot handle array input, you should set this property to be true. Otherwise some
PHP error might occur.</li>
</ul>
<blockquote class="tip"><p><strong>Tip: </strong>If you want to trim input values, you may directly use the <a href="#trim">trim</a> validator.</p>
</blockquote>
<blockquote class="tip"><p><strong>Tip: </strong>There are many PHP functions that have the signature expected for the <code>filter</code> callback.
For example to apply type casting (using e.g. <a href="http://php.net/manual/en/function.intval.php">intval</a>,
<a href="http://php.net/manual/en/function.boolval.php">boolval</a>, ...) to ensure a specific type for an attribute,
you can simply specify the function names of the filter without the need to wrap them in a closure:</p>
<pre><code class="hljs php language-php">[<span class="hljs-string">'property'</span>, <span class="hljs-string">'filter'</span>, <span class="hljs-string">'filter'</span> =&gt; <span class="hljs-string">'boolval'</span>],
[<span class="hljs-string">'property'</span>, <span class="hljs-string">'filter'</span>, <span class="hljs-string">'filter'</span> =&gt; <span class="hljs-string">'intval'</span>],
</code></pre>
</blockquote>
<h2><a href="./yii-validators-imagevalidator.html">image</a>  <span id="image"></span><a href="#image" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "primaryImage" is a valid image with proper size</span>
    [<span class="hljs-string">'primaryImage'</span>, <span class="hljs-string">'image'</span>, <span class="hljs-string">'extensions'</span> =&gt; <span class="hljs-string">'png, jpg'</span>,
        <span class="hljs-string">'minWidth'</span> =&gt; <span class="hljs-number">100</span>, <span class="hljs-string">'maxWidth'</span> =&gt; <span class="hljs-number">1000</span>,
        <span class="hljs-string">'minHeight'</span> =&gt; <span class="hljs-number">100</span>, <span class="hljs-string">'maxHeight'</span> =&gt; <span class="hljs-number">1000</span>,
    ],
]
</code></pre>
<p>This validator checks if the input value represents a valid image file. It extends from the <a href="#file">file</a> validator
and thus inherits all its properties. Besides, it supports the following additional properties specific for image
validation purpose:</p>
<ul>
<li><code>minWidth</code>: the minimum width of the image. Defaults to null, meaning no lower limit.</li>
<li><code>maxWidth</code>: the maximum width of the image. Defaults to null, meaning no upper limit.</li>
<li><code>minHeight</code>: the minimum height of the image. Defaults to null, meaning no lower limit.</li>
<li><code>maxHeight</code>: the maximum height of the image. Defaults to null, meaning no upper limit.</li>
</ul>
<h2><a href="./yii-validators-ipvalidator.html">ip</a>  <span id="ip"></span><a href="#ip" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "ip_address" is a valid IPv4 or IPv6 address</span>
    [<span class="hljs-string">'ip_address'</span>, <span class="hljs-string">'ip'</span>],

    <span class="hljs-comment">// checks if "ip_address" is a valid IPv6 address or subnet,</span>
    <span class="hljs-comment">// value will be expanded to full IPv6 notation.</span>
    [<span class="hljs-string">'ip_address'</span>, <span class="hljs-string">'ip'</span>, <span class="hljs-string">'ipv4'</span> =&gt; <span class="hljs-keyword">false</span>, <span class="hljs-string">'subnet'</span> =&gt; <span class="hljs-keyword">null</span>, <span class="hljs-string">'expandIPv6'</span> =&gt; <span class="hljs-keyword">true</span>],

    <span class="hljs-comment">// checks if "ip_address" is a valid IPv4 or IPv6 address,</span>
    <span class="hljs-comment">// allows negation character `!` at the beginning</span>
    [<span class="hljs-string">'ip_address'</span>, <span class="hljs-string">'ip'</span>, <span class="hljs-string">'negation'</span> =&gt; <span class="hljs-keyword">true</span>],
]
</code></pre>
<p>The validator checks if the attribute value is a valid IPv4/IPv6 address or subnet.
It also may change attribute's value if normalization or IPv6 expansion is enabled.</p>
<p>The validator has such configuration options:</p>
<ul>
<li><code>ipv4</code>: whether the validating value can be an IPv4 address. Defaults to true.</li>
<li><code>ipv6</code>: whether the validating value can be an IPv6 address. Defaults to true.</li>
<li><p><code>subnet</code>: whether the address can be an IP with CIDR subnet, like <code>192.168.10.0/24</code></p>
<ul>
<li><code>true</code> - the subnet is required, addresses without CIDR will be rejected</li>
<li><code>false</code> - the address can not have the CIDR</li>
<li><code>null</code> - the CIDR is optional</li>
</ul>
<p>  Defaults to false.</p>
</li>
<li><p><code>normalize</code>: whether to add the CIDR prefix with the smallest length (32 for IPv4 and 128 for IPv6) to an
address without it. Works only when <code>subnet</code> is not <code>false</code>. For example:</p>
<ul>
<li><code>10.0.1.5</code> will normalized to <code>10.0.1.5/32</code></li>
<li><code>2008:db0::1</code> will be normalized to <code>2008:db0::1/128</code></li>
</ul>
<p>  Defaults to false.</p>
</li>
<li><code>negation</code>: whether the validation address can have a negation character <code>!</code> at the beginning. Defaults to false.</li>
<li><code>expandIPv6</code>: whether to expand an IPv6 address to the full notation format.
For example, <code>2008:db0::1</code> will be expanded to <code>2008:0db0:0000:0000:0000:0000:0000:0001</code>. Defaults to false.</li>
<li><p><code>ranges</code>: array of IPv4 or IPv6 ranges that are allowed or forbidden.</p>
<p>  When the array is empty, or the option is not set, all the IP addresses are allowed.
  Otherwise, the rules are checked sequentially until the first match is found.
  IP address is forbidden, when it has not matched any of the rules.</p>
<p>  For example:
  <code>`</code>php
  [</p>
<pre><code class="hljs php">   <span class="hljs-string">'client_ip'</span>, <span class="hljs-string">'ip'</span>, <span class="hljs-string">'ranges'</span> =&gt; [
       <span class="hljs-string">'192.168.10.128'</span>
       <span class="hljs-string">'!192.168.10.0/24'</span>,
       <span class="hljs-string">'any'</span> <span class="hljs-comment">// allows any other IP addresses</span>
   ]
</code></pre>
<p>  ]
  <code>`</code>
In this example, access is allowed for all the IPv4 and IPv6 addresses excluding <code>192.168.10.0/24</code> subnet.
IPv4 address <code>192.168.10.128</code> is also allowed, because it is listed before the restriction.</p>
</li>
<li><p><code>networks</code>: array of network aliases, that can be used in <code>ranges</code>. Format of array:</p>
<ul>
<li>key - alias name</li>
<li>value - array of strings. String can be a range, IP address or another alias. String can be
  negated with <code>!</code> (independent of <code>negation</code> option).</li>
</ul>
<p>  The following aliases are defined by default:</p>
<ul>
<li><code>*</code>: <code>any</code></li>
<li><code>any</code>: <code>0.0.0.0/0, ::/0</code></li>
<li><code>private</code>: <code>10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fd00::/8</code></li>
<li><code>multicast</code>: <code>224.0.0.0/4, ff00::/8</code></li>
<li><code>linklocal</code>: <code>169.254.0.0/16, fe80::/10</code></li>
<li><code>localhost</code>: <code>127.0.0.0/8', ::1</code></li>
<li><code>documentation</code>: <code>192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 2001:db8::/32</code></li>
<li><code>system</code>: <code>multicast, linklocal, localhost, documentation</code></li>
</ul>
</li>
</ul>
<blockquote class="info"><p><strong>Info: </strong>This validator has been available since version 2.0.7.</p>
</blockquote>
<h2><a href="./yii-validators-rangevalidator.html">in</a>  <span id="in"></span><a href="#in" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "level" is 1, 2 or 3</span>
    [<span class="hljs-string">'level'</span>, <span class="hljs-string">'in'</span>, <span class="hljs-string">'range'</span> =&gt; [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]],
]
</code></pre>
<p>This validator checks if the input value can be found among the given list of values.</p>
<ul>
<li><code>range</code>: a list of given values within which the input value should be looked for.</li>
<li><code>strict</code>: whether the comparison between the input value and the given values should be strict
(both the type and value must be the same). Defaults to false.</li>
<li><code>not</code>: whether the validation result should be inverted. Defaults to false. When this property is set true,
the validator checks if the input value is NOT among the given list of values.</li>
<li><code>allowArray</code>: whether to allow the input value to be an array. When this is true and the input value is an array,
every element in the array must be found in the given list of values, or the validation would fail.</li>
</ul>
<h2><a href="./yii-validators-numbervalidator.html">integer</a>  <span id="integer"></span><a href="#integer" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "age" is an integer</span>
    [<span class="hljs-string">'age'</span>, <span class="hljs-string">'integer'</span>],
]
</code></pre>
<p>This validator checks if the input value is an integer.</p>
<ul>
<li><code>max</code>: the upper limit (inclusive) of the value. If not set, it means the validator does not check the upper limit.</li>
<li><code>min</code>: the lower limit (inclusive) of the value. If not set, it means the validator does not check the lower limit.</li>
</ul>
<h2><a href="./yii-validators-regularexpressionvalidator.html">match</a>  <span id="match"></span><a href="#match" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "username" starts with a letter and contains only word characters</span>
    [<span class="hljs-string">'username'</span>, <span class="hljs-string">'match'</span>, <span class="hljs-string">'pattern'</span> =&gt; <span class="hljs-string">'/^[a-z]\w*$/i'</span>]
]
</code></pre>
<p>This validator checks if the input value matches the specified regular expression.</p>
<ul>
<li><code>pattern</code>: the regular expression that the input value should match. This property must be set,
or an exception will be thrown.</li>
<li><code>not</code>: whether to invert the validation result. Defaults to false, meaning the validation succeeds
 only if the input value matches the pattern. If this is set true, the validation is considered
 successful only if the input value does NOT match the pattern.</li>
</ul>
<h2><a href="./yii-validators-numbervalidator.html">number</a>  <span id="number"></span><a href="#number" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "salary" is a number</span>
    [<span class="hljs-string">'salary'</span>, <span class="hljs-string">'number'</span>],
]
</code></pre>
<p>This validator checks if the input value is a number. It is equivalent to the <a href="#double">double</a> validator.</p>
<ul>
<li><code>max</code>: the upper limit (inclusive) of the value. If not set, it means the validator does not check the upper limit.</li>
<li><code>min</code>: the lower limit (inclusive) of the value. If not set, it means the validator does not check the lower limit.</li>
</ul>
<h2><a href="./yii-validators-requiredvalidator.html">required</a>  <span id="required"></span><a href="#required" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if both "username" and "password" are not empty</span>
    [[<span class="hljs-string">'username'</span>, <span class="hljs-string">'password'</span>], <span class="hljs-string">'required'</span>],
]
</code></pre>
<p>This validator checks if the input value is provided and not empty.</p>
<ul>
<li><code>requiredValue</code>: the desired value that the input should be. If not set, it means the input should not be empty.</li>
<li><code>strict</code>: whether to check data types when validating a value. Defaults to false.
When <code>requiredValue</code> is not set, if this property is true, the validator will check if the input value is
not strictly null; If this property is false, the validator will use a loose rule to determine a value is empty or not.
When <code>requiredValue</code> is set, the comparison between the input and <code>requiredValue</code> will also check data types
if this property is true.</li>
</ul>
<blockquote class="info"><p><strong>Info: </strong>How to determine if a value is empty or not is a separate topic covered
  in the <a href="guide-input-validation.html#handling-empty-inputs">Empty Values</a> section.</p>
</blockquote>
<h2><a href="./yii-validators-safevalidator.html">safe</a>  <span id="safe"></span><a href="#safe" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// marks "description" to be a safe attribute</span>
    [<span class="hljs-string">'description'</span>, <span class="hljs-string">'safe'</span>],
]
</code></pre>
<p>This validator does not perform data validation. Instead, it is used to mark an attribute to be
a <a href="guide-structure-models.html#safe-attributes">safe attribute</a>.</p>
<h2><a href="./yii-validators-stringvalidator.html">string</a>  <span id="string"></span><a href="#string" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "username" is a string whose length is between 4 and 24</span>
    [<span class="hljs-string">'username'</span>, <span class="hljs-string">'string'</span>, <span class="hljs-string">'length'</span> =&gt; [<span class="hljs-number">4</span>, <span class="hljs-number">24</span>]],
]
</code></pre>
<p>This validator checks if the input value is a valid string with certain length.</p>
<ul>
<li><code>length</code>: specifies the length limit of the input string being validated. This can be specified
 in one of the following forms:<ul>
<li>an integer: the exact length that the string should be of;</li>
<li>an array of one element: the minimum length of the input string (e.g. <code>[8]</code>). This will overwrite <code>min</code>.</li>
<li>an array of two elements: the minimum and maximum lengths of the input string (e.g. <code>[8, 128]</code>).
   This will overwrite both <code>min</code> and <code>max</code>.</li>
</ul>
</li>
<li><code>min</code>: the minimum length of the input string. If not set, it means no minimum length limit.</li>
<li><code>max</code>: the maximum length of the input string. If not set, it means no maximum length limit.</li>
<li><code>encoding</code>: the encoding of the input string to be validated. If not set, it will use the application's
<a href="./yii-base-application.html#$charset-detail">charset</a> value which defaults to <code>UTF-8</code>.</li>
</ul>
<h2><a href="./yii-validators-filtervalidator.html">trim</a>  <span id="trim"></span><a href="#trim" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// trims the white spaces surrounding "username" and "email"</span>
    [[<span class="hljs-string">'username'</span>, <span class="hljs-string">'email'</span>], <span class="hljs-string">'trim'</span>],
]
</code></pre>
<p>This validator does not perform data validation. Instead, it will trim the surrounding white spaces around
the input value. Note that if the input value is an array, it will be ignored by this validator.</p>
<h2><a href="./yii-validators-uniquevalidator.html">unique</a>  <span id="unique"></span><a href="#unique" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// a1 needs to be unique in the column represented by the "a1" attribute</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'unique'</span>],

    <span class="hljs-comment">// a1 needs to be unique, but column a2 will be used to check the uniqueness of the a1 value</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'unique'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; <span class="hljs-string">'a2'</span>],

    <span class="hljs-comment">// a1 and a2 need to be unique together, and they both will receive error message</span>
    [[<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>], <span class="hljs-string">'unique'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>]],

    <span class="hljs-comment">// a1 and a2 need to be unique together, only a1 will receive error message</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'unique'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'a2'</span>]],

    <span class="hljs-comment">// a1 needs to be unique by checking the uniqueness of both a2 and a3 (using a1 value)</span>
    [<span class="hljs-string">'a1'</span>, <span class="hljs-string">'unique'</span>, <span class="hljs-string">'targetAttribute'</span> =&gt; [<span class="hljs-string">'a2'</span>, <span class="hljs-string">'a1'</span> =&gt; <span class="hljs-string">'a3'</span>]],
]
</code></pre>
<p>This validator checks if the input value is unique in a table column. It only works
with <a href="guide-db-active-record.html">Active Record</a> model attributes. It supports validation against
either a single column or multiple columns.</p>
<ul>
<li><code>targetClass</code>: the name of the <a href="guide-db-active-record.html">Active Record</a> class that should be used
to look for the input value being validated. If not set, the class of the model currently being validated will be used.</li>
<li><code>targetAttribute</code>: the name of the attribute in <code>targetClass</code> that should be used to validate the uniqueness
of the input value. If not set, it will use the name of the attribute currently being validated.
You may use an array to validate the uniqueness of multiple columns at the same time. The array values
are the attributes that will be used to validate the uniqueness, while the array keys are the attributes
whose values are to be validated. If the key and the value are the same, you can just specify the value.</li>
<li><code>filter</code>: additional filter to be applied to the DB query used to check the uniqueness of the input value.
This can be a string or an array representing the additional query condition (refer to <a href="./yii-db-query.html#where()-detail">yii\db\Query::where()</a>
on the format of query condition), or an anonymous function with the signature <code>function ($query)</code>, where <code>$query</code>
is the <a href="./yii-db-query.html">Query</a> object that you can modify in the function.</li>
</ul>
<h2><a href="./yii-validators-urlvalidator.html">url</a>  <span id="url"></span><a href="#url" class="hashlink">&para;</a></h2><pre><code class="hljs php language-php">[
    <span class="hljs-comment">// checks if "website" is a valid URL. Prepend "http://" to the "website" attribute</span>
    <span class="hljs-comment">// if it does not have a URI scheme</span>
    [<span class="hljs-string">'website'</span>, <span class="hljs-string">'url'</span>, <span class="hljs-string">'defaultScheme'</span> =&gt; <span class="hljs-string">'http'</span>],
]
</code></pre>
<p>This validator checks if the input value is a valid URL.</p>
<ul>
<li><code>validSchemes</code>: an array specifying the URI schemes that should be considered valid. Defaults to <code>['http', 'https']</code>,
meaning both <code>http</code> and <code>https</code> URLs are considered to be valid.</li>
<li><code>defaultScheme</code>: the default URI scheme to be prepended to the input if it does not have the scheme part.
Defaults to null, meaning do not modify the input value.</li>
<li><code>enableIDN</code>: whether the validator should take into account IDN (internationalized domain names).
Defaults to false. Note that in order to use IDN validation you have to install and enable the <code>intl</code> PHP
extension, otherwise an exception would be thrown.</li>
</ul>
        <div class="toplink"><a href="#" class="h1" title="go to top"><span class="glyphicon glyphicon-arrow-up"></a></div>
    </div>
</div>


</div>

<footer class="footer">
        <p class="pull-right"><small>Page generated on Sat, 09 Jul 2016 12:16:28 +0000</small></p>
    Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></footer>

<script type="text/javascript">jQuery(document).ready(function () {
    var shiftWindow = function () { scrollBy(0, -50) };
    if (location.hash) setTimeout(shiftWindow, 1);
    window.addEventListener("hashchange", shiftWindow);
var element = document.createElement("script");
element.src = "./jssearch.index.js";
document.body.appendChild(element);

var searchBox = $('#searchbox');

// search when typing in search field
searchBox.on("keyup", function(event) {
    var query = $(this).val();

    if (query == '' || event.which == 27) {
        $('#search-resultbox').hide();
        return;
    } else if (event.which == 13) {
        var selectedLink = $('#search-resultbox a.selected');
        if (selectedLink.length != 0) {
            document.location = selectedLink.attr('href');
            return;
        }
    } else if (event.which == 38 || event.which == 40) {
        $('#search-resultbox').show();

        var selected = $('#search-resultbox a.selected');
        if (selected.length == 0) {
            $('#search-results').find('a').first().addClass('selected');
        } else {
            var next;
            if (event.which == 40) {
                next = selected.parent().next().find('a').first();
            } else {
                next = selected.parent().prev().find('a').first();
            }
            if (next.length != 0) {
                var resultbox = $('#search-results');
                var position = next.position();

//              TODO scrolling is buggy and jumps around
//                resultbox.scrollTop(Math.floor(position.top));
//                console.log(position.top);

                selected.removeClass('selected');
                next.addClass('selected');
            }
        }

        return;
    }
    $('#search-resultbox').show();
    $('#search-results').html('<li><span class="no-results">No results</span></li>');

    var result = jssearch.search(query);

    if (result.length > 0) {
        var i = 0;
        var resHtml = '';

        for (var key in result) {
            if (i++ > 20) {
                break;
            }
            resHtml = resHtml +
            '<li><a href="' + result[key].file.u.substr(3) +'"><span class="title">' + result[key].file.t + '</span>' +
            '<span class="description">' + result[key].file.d + '</span></a></li>';
        }
        $('#search-results').html(resHtml);
    }
});

// hide the search results on ESC
$(document).on("keyup", function(event) { if (event.which == 27) { $('#search-resultbox').hide(); } });
// hide search results on click to document
$(document).bind('click', function (e) { $('#search-resultbox').hide(); });
// except the following:
searchBox.bind('click', function(e) { e.stopPropagation(); });
$('#search-resultbox').bind('click', function(e) { e.stopPropagation(); });

});</script></body>
</html>
